// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2005-01-21

#include "stdafx.h"
#include <common/netmsg/gameid.h>
#include "msvr_room_war3base.h"
#include "msvr_room.h"
#include "msvr_user.h"
#include "msvr_chat.h"

namespace JoyServer
{
;

void CJoyCmdHandler_War3Base::handler_forcenick(CCommandContext& context)
{
    CJoyMainUser* pUser = context.m_user;

    CJoyCmdHandler::CParamList params;
    if(!ExtractParams(context, params))
    {
        return;
    }

    bool force = true;

    POSITION pos = params.GetHeadPosition();
    while(pos != NULL)
    {
        CJoyCmdHandler::CParamPair& paramPair = params.GetNext(pos);
        CString& paramName = paramPair.m_name;
        if(paramName == "on")
        {
            force = true;
            break;
        }
        else if(paramName == "off")
        {
            force = false;
            break;
        }
        else
        {
            pUser->SendMsg(m_room->m_roomChat->m_chatmsg_badCommand);
            return;
        }
    }

    CJoyMainRoom_War3Base::CUserRoomData_War3Base* roomData = 
        (CJoyMainRoom_War3Base::CUserRoomData_War3Base*)pUser->m_roomData;
    roomData->m_forceNick = force;
    if(force)
    {
        pUser->SendMsg(m_room->m_roomChat->m_chatmsg_forceNickOn);
    }
    else
    {
        pUser->SendMsg(m_room->m_roomChat->m_chatmsg_forceNickOff);
    }
}

} // namespace JoyServer